/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.helpers;

/**
 *
 * @author Administrator
 */
public class Crypto {

    /**
     * Key MD5, thang nao sua bo dap chet ^^
     */
    private static final String MD5_SALT_KEY = "HUYTQ";

    /**
     * ma hoa md5, cham. 1 dong code vao tau hap diem day @_@
     *
     * @param md5
     * @return
     */
    public static String getMD5(String md5) {
        try {
            java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
            byte[] array = md.digest(md5.getBytes());
            StringBuffer sb = new StringBuffer();
            for (int i = 0; i < array.length; ++i) {
                sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1, 3));
            }
            return sb.toString();
        } catch (java.security.NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * ma hoa password, cham. 1 dong code vao tau hap diem day @_@
     * @param password
     * @return
     */
    public static String encrypPassword(String password) {
        String pass = getMD5(password) + MD5_SALT_KEY;
        pass = getMD5(pass);
        return pass.toUpperCase();
    }
    
    public static void main(String[] args) {
        String hehe = "HUYTQ";
        System.out.println(encrypPassword(hehe));
    }
}
